package com.ldk.base.framework.util;

import java.util.List;

import org.ansj.domain.Term;
import org.ansj.splitWord.analysis.ToAnalysis;
import org.apache.commons.lang.StringUtils;

/**
 * 分词工具
 * @author xiangwl
 * 2016年11月22日
 * com.ycwl.platform.util
 * WordsSegUtil
 */
public class WordsSegUtil {

	/**
	 * 分词(返回以空格分开的词组)
	 * @param words
	 * @return 
	 */
	public static String parse(String words){
		String keys = "";
		//搜索关键字大于2个字符再分词
		if(!StringUtils.isBlank(words)  && words.length() > 2){
			List<Term>  termList = ToAnalysis.parse(words);
			
			for (Term term : termList) {
				keys += String.format("%s ", term.getName());
			}
		}
		else{
			keys = words;
		}
		if(!StringUtils.isBlank(keys)){
			keys = keys.trim();
		}
		return keys;
	}
}
